// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import router from './router';
import "@/assets/style.min.css";
import "@/assets/LoadingAnimation.css";
import "mint-ui/lib/style.css";
import './assets/font/iconfont.css'
import axios from 'axios';
import MintUi from 'mint-ui';
import api from './api/api'
import apiPath from './api/apiPath'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
import store from '@/store/store.js';
import '@/assets/css/my-mint.css'; //全局修改mint-UI样式  
import wx from 'wx'
Vue.prototype.$http = axios;
Vue.config.productionTip = false;
Vue.use(MintUi);
Vue.use(VueAwesomeSwiper)
Vue.prototype.$apiPath = apiPath.realApi
// Vue.prototype.$apiPath = apiPath.testApi
Vue.prototype.$apiTest = apiPath.testApi
Vue.prototype.$api = api
Vue.prototype.$wx = wx
//业务状态过滤器
Vue.filter('dateState', function (val) {
  switch (val) {
    case "0":
      return "删除";
      break;
    case "1":
      return "正常";
      break;
    case "1000":
      return "待受理";
      break;
    case "2000":
      return "待审核";
      break;
    case "3000":
      return "待复审";
      break;
    case "9000":
      return "已审结";
      break;
    case "100100":
      return "商品新增";
      break;
    case "100200":
      return "信息修改";
      break;
    case "100201":
      return "商品调价";
      break;
    case "DOCUMENT":
      return "发文通知";
      break;
    case "MACHINE":
      return "生效提醒";
      break;
  }
});

Vue.filter('dateStateto', function (val) {
  switch (val) {
    case "1":
      return "待处理";
      break;
    case "2":
      return "财务审核";
      break;
    case "3":
      return "主任确认";
      break;
    case "4":
      return "已审结";
      break;
  }
});

Vue.filter('dateStatefo', function (val) {
  switch (val) {
    case "0":
      return "权限申请";
      break;
    case "1":
      return "权限取消";
      break;
  }
});

// 空验证
Vue.filter('dateEmpty', function (val) {
  if (val == "&nbsp;" || val == "null") {
    return "";
  } else if (val == "待审核") {
    return "财务审核";
  } else {
    return val;
  }
});

// 商品状态
Vue.filter('ComState', function (val) {
  if (val == "&nbsp;" || val == "null") {
    return "";
  } else {
    if (val == "0") {
      return "无效";
    } else if (val == "1") {
      return "有效";
    }
  }
});

// 商品是否可售
Vue.filter('ComSell', function (val) {
  if (val == "&nbsp;" || val == "null") {
    return "";
  } else {
    if (val == "0") {
      return "不可售";
    } else if (val == "1") {
      return "可售";
    }
  }
});

// 商品是否散装
Vue.filter('ComBulk', function (val) {
  if (val == "&nbsp;" || val == "null") {
    return "";
  } else {
    if (val == "0") {
      return "否";
    } else if (val == "1") {
      return "是";
    }
  }
});

// 称重方式
Vue.filter('ComWeigh', function (val) {
  if (val == "&nbsp;" || val == "null") {
    return "";
  } else {
    if (val == "0") {
      return "散装称重";
    } else if (val == "1") {
      return "计价";
    }
  }
});

// 非空金额
Vue.filter('ComMoney', function (val) {
  if (val == "&nbsp;" || val == "null") {
    return "";
  } else {
    if (val.indexOf('.') > 0) {
      return '¥' + val;
    } else {
      return '¥' + val + '.00';
    }
  }
});

// 金额格式化处理方法
function fmoney(s, n) {
  /*
   * 参数说明：
   * s：要格式化的数字
   * n：保留几位小数
   * */
  n = n > 0 && n <= 20 ? n : 2;
  s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
  let l = s.split(".")[0].split("").reverse(),
    r = s.split(".")[1];
  let t = "";
  for (let i = 0; i < l.length; i++) {
    t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
  }
  return t.split("").reverse().join("") + "." + r;
}

// 非空金额
Vue.filter('ComMoney2', function (val) {
  if (val == "&nbsp;" || val == "null") {
    return "";
  } else {
    if (val > 0 || val == 0) {
      return fmoney(val, 2);
    } else {
      val = val * -1;
      return "-" + fmoney(val, 2);
    }
  }
});

// 审核状态
Vue.filter('dateApplyState', function (val) {
  if (val == "9999") {
    return "已通过";
  } if (val == "0") {
    return "未提交";
  } if (val == "999999") {
    return "已配置";
  } else {
    return "第" + val + "级审批";
  }
});

Vue.filter('dateApplyState2', function (val) {
  if (val == "9999") {
    return "已通过";
  } if (val == "0") {
    return "未提交";
  } if (val == "999999") {
    return "已配置";
  } else {
    return "待审批";
  }
});

// 审核流程状态
Vue.filter('datePerType', function (val) {
  if (val == "&nbsp;" || val == "null") {
    return "";
  } else {
    if (val == 0) {
      return "同意";
    } else if (val == 1) {
      return "驳回";
    }
  }
});

//金额过滤器
Vue.filter('moneyFilter', function (val) {
  // console.log(val)
  if (val.indexOf('.') > 0) {
    return '¥' + val;
  } else {
    return '¥' + val + '.00';
  }
});

Vue.filter('commodityName', function (val) {
  if (val.indexOf('.') > 0) {
    return '¥' + val;
  } else {
    return '¥' + val + '.00';
  }
});

// 空验证
Vue.filter('dateTime', function (val) {
  if (val == "&nbsp;" || val == "null") {
    return "";
  } else {
    let time = val.toString().split(" ");
    let timeh = time[0].split("/");
    return timeh[0] + "年" + timeh[1] + "月" + timeh[2] + "日";
  }
});

//业务名称
Vue.filter('deptNameF', function (val) {
  return val === '&nbsp;' ? '' : val;
});

//收银人员
Vue.filter('depteCashier', function (val) {
  if (val == "&nbsp;" || val == "null") {
    return "";
  } else {
    if (val.length < 6) {
      return val;
    } else {
      return val.slice(0, 4) + "..";
    }
  }
});

//财务报销流程状态
Vue.filter('processState', function(val){
  switch(val){
    case 1000:
      return '未提交';
      break;
    case 2000:
      return '办理中';
      break;
    case 3000:
      return '回退';
      break;
    case 4000:
      return '移交';
      break;
    case 9000:
      return '办结';
      break;
    case 9999:
      return '删除';
      break;
    case '':
      return '无状态';
      break;
  }
})

Vue.filter('acceptState', function(val){
  switch(val){
    case 401101:
      return '行政资产申请';
      break;
    case 401102:
      return '公务接待审批';
      break;
    case 401201:
      return '费用报销审批';
      break;
    case 401202:
      return '差旅费报销';
      break;
    case 401203:
      return '工程款支付';
      break;
    case 401204:
      return '经费预算申请';
      break;
    case 401205:
      return '固定资产处理';
      break;
    case 401301:
      return '内部转账审批';
      break;
    case 401302:
      return '大额支付';
      break;
    case 401303:
      return '支票领用审批';
      break;
    case 401304:
      return '领付款申请';
      break;
  }
})
Vue.filter('cutDate', function(date){
  if(date){
    var dd = new Date(date);
    var type = 'YYYY年MM月DD日', daynum = 0
    dd.setDate(dd.getDate() + daynum) // 获取AddDayCount天后的日期
    var y = dd.getFullYear()
    var m = (dd.getMonth() + 1) < 10 ? '0' + (dd.getMonth() + 1) : (dd.getMonth() + 1) // 获取当前月份的日期，不足10补0
    var d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号，不足10补0
    var h = dd.getHours() < 10 ? '0' + dd.getHours() : dd.getHours()
    var mi = dd.getMinutes() < 10 ? '0' + dd.getMinutes() : dd.getMinutes()
    var s = dd.getSeconds() < 10 ? '0' + dd.getSeconds() : dd.getSeconds()
    return type.replace('YYYY', y).replace('MM', m).replace('DD', d).replace('hh', h).replace('mm', mi).replace('ss', s)
  }else{
    return ''
  }
  
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store, //使用store
  template: '<App/>',
  components: { App }
})
